package com.heima.user;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import static com.heima.utils.common.IdCardUtils.*;

/**
 * @author mrchen
 * @date 2022/4/24 11:32
 */
public class AIYongyou {

    @Test
    public void idCardTest(){
        RestTemplate restTemplate = new RestTemplate();
        // 请求头的信息
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        httpHeaders.set("apicode","baf99b5d34774adf8bb3f185bfc9785e");

        // 请求参数
        Map<String,String> paramMap = new HashMap<>();
        paramMap.put("idNumber","210103195103222113");
        paramMap.put("userName","王东镇");

        HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(paramMap),httpHeaders);

        ResponseEntity<String> responseEntity = restTemplate.postForEntity("https://api.yonyoucloud.com/apis/dst/matchIdentity/matchIdentity", httpEntity, String.class);
        System.out.println(responseEntity.getBody());
    }

    @Test
    public void orcTest(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("apicode","3cc49b13c720444096329c5398621f79");
        httpHeaders.setContentType(MediaType.APPLICATION_JSON); // json
        Map<String,String> map = new HashMap<>();
        map.put("image","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/b58f8c5494eef01f8b9ace11e1fe9925bd317d5c.jpg");
        map.put("imageType","URL");
        map.put("ocrType","1");
        HttpEntity<String> formEntry = new HttpEntity<>(JSON.toJSONString(map), httpHeaders); // 封装请求参数
        ResponseEntity<String> response = restTemplate.postForEntity("https://api.yonyoucloud.com/apis/dst/IdcardOCR/IdcardOCR", formEntry, String.class);// 发送一个post请求
        String responseJson = response.toString();
        //System.out.println(responseJson);
        int i = responseJson.indexOf(",")+1;
        int j = responseJson.indexOf("[")-1;
        responseJson = responseJson.substring(i,j);
        //System.out.println(responseJson);

        JSONObject object= JSONObject.parseObject(responseJson);
        System.out.println(object.get("message"));
//        System.err.println(object.getJSONObject("data").get("name"));

    }
    @Test
    public void liveTest(){
        RestTemplate restTemplate = new RestTemplate();
        // 请求头的信息
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        httpHeaders.set("apicode","16a7999d10be4b5c9dcbdfd742a328a6");

        // 请求参数
        Map<String,String> map = new HashMap<>();
        map.put("image","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/Snipaste_2022-05-13_19-44-54.png");
        map.put("imageType","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/Snipaste_2022-05-13_19-44-54.png");


        HttpEntity<String> httpEntity = new HttpEntity<>(JSON.toJSONString(map),httpHeaders);

        ResponseEntity<String> responseEntity = restTemplate.postForEntity("https://api.yonyoucloud.com/apis/dst/Biologicalexamination/Biologicalexamination", httpEntity, String.class);
        System.out.println(responseEntity.getBody());

        //httpHeaders.add("apicode","16a7999d10be4b5c9dcbdfd742a328a6");

        //map.put("image","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/Snipaste_2022-05-13_19-44-54.png");
        //map.put("imageType","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/Snipaste_2022-05-13_19-44-54.png");


    }
    @Test
    public void liveTest1(){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("apicode","d4cbe715e4f34605bfc7d7063ecf92e9");
        httpHeaders.setContentType(MediaType.APPLICATION_JSON); // json
        Map<String,String> map = new HashMap<>();
        map.put("idCardImage","https://hmtt122.oss-cn-shanghai.aliyuncs.com/demo_idcard.png");
        map.put("imageType","URL");
        map.put("liveImage","https://haru1987-hmtt.oss-cn-shanghai.aliyuncs.com/Snipaste_2022-05-13_19-44-54.png");
        HttpEntity<String> formEntry = new HttpEntity<>(JSON.toJSONString(map), httpHeaders); // 封装请求参数
        ResponseEntity<String> response = restTemplate
                .postForEntity("https://api.yonyoucloud.com/apis/dst/ComparisonsofPersonsandDocuments/ComparisonsofPersonsandDocuments", formEntry, String.class);// 发送一个post请求
        System.out.println(response);
    }



}
